package com.show.mytest;

public class ProductThread implements Runnable {
    private Resource r;

    public ProductThread(Resource r) {
        this.r = r;
    }

    int index = 0;

    @Override
    public void run() {
        while (true){
            synchronized (r) {
                if (index % 2 == 0) {
                    r.setName("小王");
                    r.setGender("男");
                } else {
                    r.setName("小美");
                    r.setGender("女");
                }
                try {
                    r.notify();
                    r.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            index++;
        }
    }
}
